﻿Imports System

Namespace System.Workflow.ComponentModel
    Friend Class ActivityExecutor([Of] T As Activity)
        Inherits ActivityExecutor
        ' Methods
        Public NotOverridable Overrides Function Cancel(ByVal activity As Activity, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            Return Me.Cancel(DirectCast(activity, T), executionContext)
        End Function

        Protected Overridable Function Cancel(ByVal activity As T, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            If (activity Is Nothing) Then
                Throw New ArgumentNullException("activity")
            End If
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Return activity.Cancel(executionContext)
        End Function

        Public NotOverridable Overrides Function Compensate(ByVal activity As Activity, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            Return Me.Compensate(DirectCast(activity, T), executionContext)
        End Function

        Protected Overridable Function Compensate(ByVal activity As T, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            If (activity Is Nothing) Then
                Throw New ArgumentNullException("activity")
            End If
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Return DirectCast(activity, ICompensatableActivity).Compensate(executionContext)
        End Function

        Protected Overridable Function Execute(ByVal activity As T, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            If (activity Is Nothing) Then
                Throw New ArgumentNullException("activity")
            End If
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Return activity.Execute(executionContext)
        End Function

        Public NotOverridable Overrides Function Execute(ByVal activity As Activity, ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            Return Me.Execute(DirectCast(activity, T), executionContext)
        End Function

        Protected Overridable Function HandleFault(ByVal activity As T, ByVal executionContext As ActivityExecutionContext, ByVal exception As Exception) As ActivityExecutionStatus
            If (activity Is Nothing) Then
                Throw New ArgumentNullException("activity")
            End If
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Return activity.HandleFault(executionContext, exception)
        End Function

        Public NotOverridable Overrides Function HandleFault(ByVal activity As Activity, ByVal executionContext As ActivityExecutionContext, ByVal exception As Exception) As ActivityExecutionStatus
            Return Me.HandleFault(DirectCast(activity, T), executionContext, exception)
        End Function

    End Class
End Namespace

